//
// Created by Tony on 2024/7/7.
//

#include "GET_STATIC.h"
#include "../rt_code/Class.h"
#include <memory>

namespace Runtime {

void GET_STATIC::execute(RtData::Frame& frame) {
    auto& curMethod = frame.getMethod();
    shared_ptr<RtCode::Class> curClass = curMethod->getOwnerClass();
    auto& curConstPool = curClass->getConstantPool();
    auto* fieldRef = curConstPool.getFieldRef(mIndex);
    auto field = fieldRef->resolvedField();
    auto clazz = field->getOwnerClass();

    if (!clazz->isInitStarted()) {
        initClass(frame, clazz);
        return;
    }

    auto& staticVars = clazz->getStaticVars();
    auto slotId = field->getSlotId();
    frame.pushValue(staticVars[slotId].getValue());
}

} // namespace Runtime
